#include <iostream>
#include <iterator>
#include <algorithm>
#include <ctime>
#include <cstdlib>

using namespace std;

class mi_rand
{
    public:
        mi_rand (int start_pos, int end_pos) : a(start_pos), b(end_pos) 
        {
            if (a > b) swap(a,b);
            srand ((unsigned) time(NULL));
        }

        unsigned operator () () 
        {
            return rand() % (b-a+1) + a;
        }

    private:
        int a, b;
};

void selectionSort (int *array, int size)
{
    if (size == 1) return;
    int *min = array;
    for (int j = 1; j < size; ++j)
        if (*min > array[j]) min = &array[j];
    swap (*min, array[0]);
    selectionSort (array+1, size-1);
}

int main()
{
    const int SIZE = 10;
    int array[SIZE];
    generate_n (array, SIZE, mi_rand(10,200));
    
    copy (array, &array[SIZE], 
          ostream_iterator<int> (cout, " "));
    cout << endl;

    selectionSort (array, SIZE);

    copy (array, &array[SIZE], 
          ostream_iterator<int> (cout, " "));
    cout << endl;

    return 0;
}

